package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesTaskDetails;
import com.ruoyi.mes.service.IMesTaskDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产任务-明细Controller
 * 
 * @author ruoyi
 * @date 2021-10-27
 */
@RestController
@RequestMapping("/taskDetails")
public class MesTaskDetailsController extends BaseController
{
    @Autowired
    private IMesTaskDetailsService mesTaskDetailsService;

    /**
     * 查询生产任务-明细列表
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(MesTaskDetails mesTaskDetails)
    {
        startPage();
        List<MesTaskDetails> list = mesTaskDetailsService.selectMesTaskDetailsList(mesTaskDetails);
        return getDataTable(list);
    }

    /**
     * 查询指定生产任务下的所有工序
     */
    @GetMapping("/listByTaskUuid")
    public TableDataInfo listByTaskUuid(MesTaskDetails mesTaskDetails)
    {
        startPage();
        List<MesTaskDetails> list = mesTaskDetailsService.selectMesTaskDetailsListByTaskUuid(mesTaskDetails);
        return getDataTable(list);
    }

    /**
     * 导出生产任务-明细列表
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:export")
    @Log(title = "生产任务-明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesTaskDetails mesTaskDetails) throws IOException
    {
        List<MesTaskDetails> list = mesTaskDetailsService.selectMesTaskDetailsList(mesTaskDetails);
        ExcelUtil<MesTaskDetails> util = new ExcelUtil<MesTaskDetails>(MesTaskDetails.class);
        util.exportExcel(response, list, "生产任务-明细数据");
    }

    /**
     * 获取生产任务-明细详细信息
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:query")
    @GetMapping(value = "/{taskDetailUuid}")
    public AjaxResult getInfo(@PathVariable("taskDetailUuid") String taskDetailUuid)
    {
        return AjaxResult.success(mesTaskDetailsService.selectMesTaskDetailsByTaskDetailUuid(taskDetailUuid));
    }

    /**
     * 新增生产任务-明细
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:add")
    @Log(title = "生产任务-明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesTaskDetails mesTaskDetails)
    {
        return toAjax(mesTaskDetailsService.insertMesTaskDetails(mesTaskDetails));
    }

    /**
     * 修改生产任务-明细
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:edit")
    @Log(title = "生产任务-明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesTaskDetails mesTaskDetails)
    {
        return toAjax(mesTaskDetailsService.updateMesTaskDetails(mesTaskDetails));
    }

    /**
     * 删除生产任务-明细
     */
    @PreAuthorize(hasPermi = "mes:taskDetails:remove")
    @Log(title = "生产任务-明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskDetailUuids}")
    public AjaxResult remove(@PathVariable String[] taskDetailUuids)
    {
        return toAjax(mesTaskDetailsService.deleteMesTaskDetailsByTaskDetailUuids(taskDetailUuids));
    }
}
